package com.qianclass.talklive.app.json.ImSendMessge;

import com.google.gson.Gson;
import com.qianclass.talklive.app.bean.ClearGraffitoBean;
import com.qianclass.talklive.app.bean.RevokeGraffitiBean;
import com.qianclass.talklive.app.bean.RevokeH5GraffitiBean;
import com.qianclass.talklive.app.utils.Constant;
import com.qianclass.talklive.app.utils.LogUtil;
import com.qianclass.talklive.app.utils.ThreadUtils;

import java.util.ArrayList;
import java.util.List;

import static com.qianclass.talklive.app.activity.VideoActivity.egine;


/**
 * 清除涂鸦笔迹
 * {"message":{"type":"whiteboard","whiteboard":{"currentpage":1,"fileid":10009885,"imageurl":"","pagenum":14,"subcommand":"removeall"}}}
 */

public class SendClearGraffitoMessage {

    /**
     * @param currentpage
     * @param fileId
     * @param pagenum
     * @param group
     */
    public static void sendMessge(int currentpage, int fileId, int pagenum, final String group) {
        try {

            ClearGraffitoBean clearGraffitoBean = new ClearGraffitoBean();
            ClearGraffitoBean.MessageBean messageBean = new ClearGraffitoBean.MessageBean();
            ClearGraffitoBean.MessageBean.WhiteboardBean whiteboardBean = new ClearGraffitoBean.MessageBean.WhiteboardBean();

            whiteboardBean.setSubcommand("removeall");
            whiteboardBean.setCurrentpage(currentpage);
            whiteboardBean.setFileid(fileId);
            whiteboardBean.setImageurl("");
            whiteboardBean.setPagenum(pagenum);

            messageBean.setType("whiteboard");
            messageBean.setWhiteboard(whiteboardBean);

            clearGraffitoBean.setMessage(messageBean);

            Gson gson = new Gson();
            final String jsonString = gson.toJson(clearGraffitoBean);
            ThreadUtils.runOnSubThread(new Runnable() {
                @Override
                public void run() {
                    egine.SendGroupMessage(Constant.CONTROLMSGTYPE, group, jsonString);
                }
            });
            LogUtil.i("清屏" ,jsonString);
        } catch (Exception e){
            LogUtil.i("清屏" , "发送信息失败");
        }

    }

     /*{"message":{"type":"whiteboard","whiteboard":{"currentpage":1,"fileid":1,"imageurl":"","objid":[244446000],"pagenum":10,"subcommand":"removeobject"}}}*/


    public static void revokeGraffiti(int currentpage, int fileId, int pagenum, int objectId, final String group) {
        RevokeGraffitiBean revokeGraffitiBean = new RevokeGraffitiBean();
        RevokeGraffitiBean.MessageBean messageBean = new RevokeGraffitiBean.MessageBean();
        RevokeGraffitiBean.MessageBean.WhiteboardBean whiteboardBean = new RevokeGraffitiBean.MessageBean.WhiteboardBean();
        List<Integer> list = new ArrayList<>();
        list.add(objectId);

        whiteboardBean.setSubcommand("removeobject");
        whiteboardBean.setCurrentpage(currentpage);
        whiteboardBean.setFileid(fileId);
        whiteboardBean.setImageurl("");
        whiteboardBean.setPagenum(pagenum);
        whiteboardBean.setObjid(list);

        messageBean.setType("whiteboard");
        messageBean.setWhiteboard(whiteboardBean);

        revokeGraffitiBean.setMessage(messageBean);

        Gson gson = new Gson();
        final String jsonString = gson.toJson(revokeGraffitiBean);
        ThreadUtils.runOnSubThread(new Runnable() {
            @Override
            public void run() {
                egine.SendGroupMessage(Constant.WHITEBOARDMSGTYPE, group, jsonString);
            }
        });
    }

    /*message : {"type":"whiteboard","whiteboard":{"fileid":20171212,"currentpage":2,"subcommand":"removegraffiti","objid":12345678}}*/

    public static void revokeH5Graffiti(int currentpage, int fileId, int objectId, final String group) {
        RevokeH5GraffitiBean revokeH5GraffitiBean = new RevokeH5GraffitiBean();
        RevokeH5GraffitiBean.MessageBean messageBean = new RevokeH5GraffitiBean.MessageBean();
        RevokeH5GraffitiBean.MessageBean.WhiteboardBean whiteboardBean = new RevokeH5GraffitiBean.MessageBean.WhiteboardBean();

        whiteboardBean.setSubcommand("removegraffiti");
        whiteboardBean.setCurrentpage(currentpage);
        whiteboardBean.setFileid(fileId);
        whiteboardBean.setObjid(objectId);

        messageBean.setType("whiteboard");
        messageBean.setWhiteboard(whiteboardBean);

        revokeH5GraffitiBean.setMessage(messageBean);

        Gson gson = new Gson();
        final String jsonString = gson.toJson(revokeH5GraffitiBean);

        ThreadUtils.runOnSubThread(new Runnable() {
            @Override
            public void run() {
                egine.SendGroupMessage(Constant.WHITEBOARDMSGTYPE, group, jsonString);
            }
        });
    }

}
